<?php

abstract class CPageBase extends CBase
{
	protected $_baseUrl = "";
	
	function __construct($baseUrl=""){
		$this->_baseUrl = $baseUrl;
	}
	
	protected function getPageUrl($page)
	{
		if(strpos($this->_baseUrl,"?")!==false)
		{
			return $this->_baseUrl."&page=".$page;
		}
		return $this->_baseUrl."?page=".$page;
	}
	
	public abstract function showPage($curPage,$pageSize,$rowCount);

	protected function pageInfo($curPage,$pageSize,$rowCount)
	{
		//首页
		//上一页
		//下一页
		//中间页面
		//尾页
		//总页数
		//当前页数
		
		$firstPageInfo = array();
		$priPageInfo = array();
		$nextPageInfo = array();
		$normalPageInfo = array();
		$lastPageInfo = array();
		
		$pageTotal = ceil($rowCount/$pageSize);
		
		if($curPage == 0)
		{
			$curPage = 1;
		}
		
		if($curPage==1)
		{
			$firstPageInfo["enabled"] = false;
			$firstPageInfo["page"] = "";
			
			$priPageInfo["enabled"] = false;
			$priPageInfo["page"] = "";
		}
		else
		{
			$firstPageInfo["enabled"] = true;
			$firstPageInfo["page"] = "1";
			
			$priPageInfo["enabled"] = true;
			$priPageInfo["page"] = $curPage - 1;
		}
		
		if($curPage>=$pageTotal)
		{
			$lastPageInfo["enabled"] = false;
			$lastPageInfo["page"] = "";
			
			$nextPageInfo["enabled"] = false;
			$nextPageInfo["page"] = "";
		}
		else
		{
			$lastPageInfo["enabled"] = true;
			$lastPageInfo["page"] = $pageTotal;
			
			$nextPageInfo["enabled"] = true;
			$nextPageInfo["page"] = $curPage+1;
		}
		
		return array("pageTotal"=>$pageTotal,"firstPageInfo"=>$firstPageInfo,"priPageInfo"=>$priPageInfo,
					 "nextPageInfo"=>$nextPageInfo,"lastPageInfo"=>$lastPageInfo
		);
	}
}

?>